var b00 = JSON.parse(sessionStorage.getItem("b1"));
var pageSize01;
$(function () {
    $.ajax({
        url: "/customCount",      //请求接口的地址
        type: "GET",
        data: {
            "current": 1,
            "customname": b00
        },
        dataType: "json",
        success: function (res) {
            $("#tbList").html("")
            var uui = 0;
            var dd = res;
            for (var i in dd.records) {
                var tr2 = "<tr></tr>";
                $("#customCount02").append(tr2);
                var li2 = $("#customCount02 tr").eq(i);
                uui += 1;
                var str1 = "<td>" + uui + "</td>";
                str1 += "<td>" + dd.records[i].customname + "</td>";
                str1 += "<td id='orderid001'>" + dd.records[i].orderid + "</td>";
                str1 += "<td>" + dd.records[i].purchaseNum + "</td>";
                str1 += "<td>" + dd.records[i].prototal2 + "</td>";
                str1 += "<td>" + dd.records[i].ordertime + "</td>";
                str1 += "<td>" + dd.records[i].uname + "</td>";
                str1 += '<td><a href="../../../market/order/orderView.html" class="tablelink">查看详情</a></td>';
                str1 += '<div id="hiddd0">+dd.records[i].orderid+</div>';
                li2.prepend(str1);
            }//在控制台输出返回结果

            $('.blue').eq(0).text(dd.total)
            $('.blue').eq(1).text(dd.current)
            cliOrder()
            pageSize01 = Number(dd.pages)
            var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
            if (pageSize01 >= 3) {
                for (var i = 1; i <= pageSize01; i++) {
                    if (i == pageSize01) {
                        pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                    } else {
                        pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                    }
                    if (i == pageSize01 - 2) {
                        pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                        pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                        break;
                    }

                }
            } else {
                for (var i = 1; i <= pageSize01; i++) {
                    if (i == pageSize01) {
                        pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                    } else {
                        pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                    }
                }
            }
            pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
            $('.paginList').html(pageStr)
            pageOnclik0101()
        }, error: function (r) {
            alert("!!!")
        }
    })
})

// 点击商品详情
function cliOrder() {
    $(".tablelink").click(function () {
        var sum1 = $(this).parent().parent().children("td").eq(0).text();
        var a = $(this).parent().parent().children("#orderid001").text();
        sessionStorage.removeItem("a1");
        sessionStorage.removeItem("sum1");
        sessionStorage.setItem("a1", JSON.stringify(a));
        sessionStorage.setItem("sum1", JSON.stringify(sum1));
    });
}


//分页点击
function pageOnclik0101() {
    $(".paginItem").click(function () {
        var click = $(this).children("a").text();
        var current = $('.blue').eq(1).text();
        if (current == click) {
            $(this).children("a").addClass("more")
        } else {
            if (click == "...") {
            } else if (click == '') {
                if ('<a href="javascript:;"><span class="pagepre"></span></a>' == $(this).html()) {
                    if (current != 1) {
                        current -= 1;
                        $("#tbList").html("")
                        $.ajax({
                            url: "/customCount",      //请求接口的地址
                            type: "GET",
                            data: {
                                "current": current
                            },
                            dataType: "json",
                            success: function (res) {
                                $("#tbList").html("")
                                var uui = 0;
                                var dd = res;
                                for (var i in dd.records) {
                                    var tr1 = "<tr></tr>";
                                    $("#tbList").append(tr1);
                                    var li = $("#tbList tr").eq(i);
                                    uui += 1;
                                    var str1 = "<td>" + uui + "</td>";
                                    str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                                    str1 += "<td>" + dd.records[i].site + "</td>";
                                    str1 += "<td>" + dd.records[i].purchaseNum + "</td>";
                                    str1 += "<td>" + dd.records[i].prototal2 + "</td>";
                                    str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                                    li.prepend(str1);
                                }
                                $('.blue').eq(0).text(dd.total)
                                $('.blue').eq(1).text(dd.current)
                                cliOrder()
                                pageSize01=Number(dd.pages)
                                var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                                if (pageSize01 >= 3) {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                        if (i == pageSize01 - 2) {
                                            pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                                            break;
                                        }

                                    }
                                } else {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                    }
                                }
                                pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                                $('.paginList').html(pageStr)
                                pageOnclik0101()
                            }, error: function (r) {
                                alert("!!!")
                            }
                        })
                    }
                } else {
                    if (current != pageSize01) {
                        var currentInt=parseInt(current)+1;
                        $("#tbList").html("")
                        $.ajax({
                            url: "/customCount",      //请求接口的地址
                            type: "GET",
                            data: {
                                "current": currentInt
                            },
                            dataType: "json",
                            success: function (res) {
                                $("#tbList").html("")
                                var uui = 0;
                                var dd = res;
                                for (var i in dd.records) {
                                    var tr1 = "<tr></tr>";
                                    $("#tbList").append(tr1);
                                    var li = $("#tbList tr").eq(i);
                                    uui += 1;
                                    var str1 = "<td>" + uui + "</td>";
                                    str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                                    str1 += "<td>" + dd.records[i].site + "</td>";
                                    str1 += "<td>" + dd.records[i].purchaseNum + "</td>";
                                    str1 += "<td>" + dd.records[i].prototal + "</td>";
                                    str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                                    li.prepend(str1);
                                }
                                $('.blue').eq(0).text(dd.total)
                                $('.blue').eq(1).text(dd.current)
                                cliOrder()
                                pageSize01=Number(dd.pages)
                                var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                                if (pageSize01 >= 3) {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                        if (i == pageSize01 - 2) {
                                            pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                                            break;
                                        }

                                    }
                                } else {
                                    for (var i = 1; i <= pageSize01; i++) {
                                        if (i == pageSize01) {
                                            pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                        } else {
                                            pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                        }
                                    }
                                }
                                pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                                $('.paginList').html(pageStr)
                                pageOnclik0101()
                            }, error: function (r) {
                                alert("!!!")
                            }
                        })
                    }
                }

            } else {
                $("#tbList").html("")
                $.ajax({
                    url: "/customCount",      //请求接口的地址
                    type: "GET",
                    data: {
                        "current": click
                    },
                    dataType: "json",
                    success: function (res) {
                        $("#tbList").html("")
                        var uui = 0;
                        var dd = res;
                        for (var i in dd.records) {
                            var tr1 = "<tr></tr>";
                            $("#tbList").append(tr1);
                            var li = $("#tbList tr").eq(i);
                            uui += 1;
                            var str1 = "<td>" + uui + "</td>";
                            str1 += "<td id='custname01'>" + dd.records[i].customname + "</td>";
                            str1 += "<td>" + dd.records[i].site + "</td>";
                            str1 += "<td>" + dd.records[i].purchaseNum + "</td>";
                            str1 += "<td>" + dd.records[i].prototal + "</td>";
                            str1 += '<td><a href="salesView.html" class="tablelink" >查看详情</a></td>';
                            li.prepend(str1);
                        }
                        $('.blue').eq(0).text(dd.total)
                        $('.blue').eq(1).text(dd.current)
                        cliOrder()
                        pageSize01=Number(dd.pages)
                        var pageStr = '<li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>'
                        if (pageSize01 >= 3) {
                            for (var i = 1; i <= pageSize01; i++) {
                                if (i == pageSize01) {
                                    pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                } else {
                                    pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                }
                                if (i == pageSize01 - 2) {
                                    pageStr += '<li class="paginItem more"><a href="javascript:;">...</a></li>'
                                    pageStr += '<li class="paginItem"><a href="javascript:;">' + pageSize01 + '</a></li>'
                                    break;
                                }

                            }
                        } else {
                            for (var i = 1; i <= pageSize01; i++) {
                                if (i == pageSize01) {
                                    pageStr += '<li class="paginItem current more" id="current01"><a href="javascript:;">' + i + '</a></li>'
                                } else {
                                    pageStr += '<li class="paginItem"><a href="javascript:;">' + i + '</a></li>'
                                }
                            }
                        }
                        pageStr += '<li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>'
                        $('.paginList').html(pageStr)
                        pageOnclik0101()
                    }, error: function (r) {
                        alert("!!!")
                    }
                })
            }
        }

    })
}
